home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Using Graphics Containers / Nested Graphics Containers / Several Layers of Nested Containers / GDITEST68.dpr
Encoding:
Text File  |  2003-10-15  |  3.1 KB  |  114 lines

  1. program GDITEST68;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10. Procedure OnPaint(DC: HDC);
  11. var
  12.   graphics : TGPGraphics;
  13.   innerContainer, outerContainer: GraphicsContainer;
  14.   brush: TGPSolidBrush;
  15.   FontFamily: TGPFontFamily;
  16.   Font: TGPFont;
  17. begin
  18.   graphics := TGPGraphics.Create(DC);
  19.  
  20.   brush:= TGPSolidBrush.Create(MakeColor(255, 0, 0, 255));
  21.   FontFamily := TGPFontFamily.Create('Times New Roman');
  22.   Font := TGPFont.Create(fontFamily, 36, FontStyleRegular, UnitPixel);
  23.  
  24.   graphics.SetTextRenderingHint(TextRenderingHintAntiAlias);
  25.  
  26.   outerContainer := graphics.BeginContainer();
  27.  
  28.      graphics.SetTextRenderingHint(TextRenderingHintSingleBitPerPixel);
  29.  
  30.      innerContainer := graphics.BeginContainer();
  31.         graphics.SetTextRenderingHint(TextRenderingHintAntiAlias);
  32.         graphics.DrawString('Inner Container', 15, font,
  33.            MakePoint(20.0, 10.0), brush);
  34.      graphics.EndContainer(innerContainer);
  35.  
  36.      graphics.DrawString('Outer Container', 15, font, MakePoint(20.0, 50.0), brush);
  37.  
  38.   graphics.EndContainer(outerContainer);
  39.  
  40.   graphics.DrawString('Graphics Object', 15, font, MakePoint(20.0, 90.0), brush);
  41.  
  42.   Font.Free;
  43.   brush.Free;
  44.   FontFamily.Free;
  45.   graphics.Free;
  46. end;
  47.  
  48.  
  49. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  50. var
  51.   Handle: HDC;
  52.   ps: PAINTSTRUCT;
  53. begin
  54.   case message of
  55.     WM_PAINT:
  56.       begin
  57.         Handle := BeginPaint(Wnd, ps);
  58.         OnPaint(Handle);
  59.         EndPaint(Wnd, ps);
  60.         result := 0;
  61.       end;
  62.  
  63.     WM_DESTROY:
  64.       begin
  65.         PostQuitMessage(0);
  66.         result := 0;
  67.       end;
  68.  
  69.    else
  70.       result := DefWindowProc(Wnd, message, wParam, lParam);
  71.    end;
  72. end;
  73.  
  74. var
  75.   hWnd     : THandle;
  76.   Msg      : TMsg;
  77.   wndClass : TWndClass;
  78. begin
  79.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  80.    wndClass.lpfnWndProc    := @WndProc;
  81.    wndClass.cbClsExtra     := 0;
  82.    wndClass.cbWndExtra     := 0;
  83.    wndClass.hInstance      := hInstance;
  84.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  85.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  86.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  87.    wndClass.lpszMenuName   := nil;
  88.    wndClass.lpszClassName  := 'GettingStarted';
  89.  
  90.    RegisterClass(wndClass);
  91.  
  92.    hWnd := CreateWindow(
  93.       'GettingStarted',       // window class name
  94.       'Several Layers of Nested Containers',      // window caption
  95.       WS_OVERLAPPEDWINDOW,    // window style
  96.       Integer(CW_USEDEFAULT), // initial x position
  97.       Integer(CW_USEDEFAULT), // initial y position
  98.       Integer(CW_USEDEFAULT), // initial x size
  99.       Integer(CW_USEDEFAULT), // initial y size
  100.       0,                      // parent window handle
  101.       0,                      // window menu handle
  102.       hInstance,              // program instance handle
  103.       nil);                   // creation parameters
  104.  
  105.    ShowWindow(hWnd, SW_SHOW);
  106.    UpdateWindow(hWnd);
  107.  
  108.    while(GetMessage(msg, 0, 0, 0)) do
  109.    begin
  110.       TranslateMessage(msg);
  111.       DispatchMessage(msg);
  112.    end;
  113. end.
  114.